package org.itec.yeast.trdo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.itec.yeast.db.DataManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TRSmfSQL {
	private static final Logger log = LoggerFactory.getLogger(TRSmfSQL.class);
	private static final String SQL_INSERT = "insert into smf("
											+ "STRAIN_idSTRAIN, Score, Standard_Deviation, SMFCondition"
											+ ") values (?, ?, ?, ?)";
	
	private Object[] getParams(TRSmf smf){
		Object[] params = new Object[]{
				smf.getStrainID(),
				smf.getScore(),
				smf.getStandardDeviation(),
				smf.getCondition()
		};
		
		return params;
	}
	
	public void insert(TRSmf smf){
		Object[] params = getParams(smf);
		int result = DataManager.executeUpdate(SQL_INSERT, params);
		if (result != 0){
			log.info("插入SMF数据成功");
		} else {
			log.info("未插入SMF数据");
		}
	}
	
	public void insert(List<TRSmf> sfms){
		int result = -1;
		List<Object[]> list = new ArrayList<Object[]>();
		long start = System.currentTimeMillis();
		for (int i = 0; i < sfms.size(); i++){
			TRSmf smf = sfms.get(i);
			Object[] params = getParams(smf);
			list.add(params);
		}
		
		result = DataManager.executeBatchInsert(SQL_INSERT, list);
		long end = System.currentTimeMillis();
		log.info("插入" + result + "条Smf记录，共用" + (end - start) + "ms");
	}
	
	public boolean isSMFExist(TRSmf smf){
		boolean exist = false;
		String sql = "select idSMF from smf where STRAIN_idSTRAIN = ?";
		Object[] params = new Object[]{smf.getStrainID()};
		List list = DataManager.executeQuery(sql, params);
		if (list != null && list.size() > 0){
			exist = true;
		}
		
		return exist;
	}
	
	
	public static void main(String[] args){
		TRAlleleSQL sql = new TRAlleleSQL();
	}
}
